package com.clickpaas.governmentcloud.thread;

import com.clickpaas.governmentcloud.common.ConstantExt;
import com.clickpaas.governmentcloud.entity.policyEntity.PolicyEntity;
import com.clickpaas.governmentcloud.service.policymatchextservice.MatchExtMainService;
import com.clickpaas.governmentcloud.utils.dateutils.DateUtils;
import lombok.extern.slf4j.Slf4j;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Slf4j
public class BatchDealMatchThread extends Thread{
    private List<PolicyEntity> list;
    private Map<Long,Integer> map;
    private MatchExtMainService matchExtMainService;

    public BatchDealMatchThread(List<PolicyEntity> list,Map<Long,Integer> map,MatchExtMainService matchExtMainService){
        this.list = list;
        this.map = map;
        this.matchExtMainService = matchExtMainService;
    }

    @Override
    public void run() {

        int pcount = map.get(ConstantExt._PCOUNT);
        int i = map.get(Thread.currentThread().getId());

        for(;i<list.size();i+=pcount){

            PolicyEntity policyEntity = list.get(i);
            ArrayList<String> qualiList = new ArrayList<>();
            String isHighTech = policyEntity.getIsHighTech();
            String isTech = policyEntity.getIsTech();
            String isZJTX = policyEntity.getIsZjtx();
            if(ConstantExt._YES.equals(isHighTech)){
                qualiList.add("高新技术企业");
            }
            if(ConstantExt._YES.equals(isTech)){
                qualiList.add("软件或科技服务类");
            }
            if(ConstantExt._YES.equals(isZJTX)){
                qualiList.add("专精特新企业");
            }
            //企业资质
            policyEntity.setEnterpriseQualification(qualiList);
            String registeredTime = policyEntity.getRegisteredTime();
            try {
                policyEntity.setRegisteredTime(DateUtils.dateConvers(registeredTime));
            } catch (ParseException e) {
                log.info("注册时间转换报错：【{}】",e);
            }
            policyEntity.setTypeofDataSource(ConstantExt.BATCH_PROCESSING);
            matchExtMainService.fastMExecutMatchPolicy(policyEntity);
        }
    }
}
